<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="../">
<head>
  <meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Performance &mdash; The Logtalk Handbook v3.93.0-b01 documentation</title>
      <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=d75fae25" />
      <link rel="stylesheet" type="text/css" href="../_static/css/theme.css?v=19f00094" />
      <link rel="stylesheet" type="text/css" href="../_static/css/custom.css?v=396eccfe" />

  
  <!--[if lt IE 9]>
    <script src="../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
        <script src="../_static/jquery.js?v=5d32c60e"></script>
        <script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
        <script src="../_static/documentation_options.js?v=c8100655"></script>
        <script src="../_static/doctools.js?v=9a2dae69"></script>
        <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="../_static/js/theme.js"></script>
    <!-- begin favicon -->
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
    <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
    <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
    <link rel="manifest" href="/site.webmanifest" />
    <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5" />
    <meta name="msapplication-TileColor" content="#355b95" />
    <meta name="theme-color" content="#ffffff" />
    <!-- end favicon -->
    
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Licensing" href="licensing.html" />
    <link rel="prev" title="Deployment" href="deployment.html" />
   
</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >

          
          
          <a href="../index.html" class="icon icon-home">
            The Logtalk Handbook
              <img src="../_static/logtalk.gif" class="logo" alt="Logo"/>
          </a>
              <div class="version">
                3.93.0
              </div>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
    
              <p class="caption" role="heading"><span class="caption-text">Contents</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../userman/index.html">User Manual</a></li>
<li class="toctree-l1"><a class="reference internal" href="../refman/index.html">Reference Manual</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Tutorial</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">FAQ</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="general.html">General</a></li>
<li class="toctree-l2"><a class="reference internal" href="compatibility.html">Compatibility</a></li>
<li class="toctree-l2"><a class="reference internal" href="installation.html">Installation</a></li>
<li class="toctree-l2"><a class="reference internal" href="portability.html">Portability</a></li>
<li class="toctree-l2"><a class="reference internal" href="programming.html">Programming</a></li>
<li class="toctree-l2"><a class="reference internal" href="troubleshooting.html">Troubleshooting</a></li>
<li class="toctree-l2"><a class="reference internal" href="usability.html">Usability</a></li>
<li class="toctree-l2"><a class="reference internal" href="deployment.html">Deployment</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Performance</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#is-logtalk-implemented-as-a-meta-interpreter">Is Logtalk implemented as a meta-interpreter?</a></li>
<li class="toctree-l3"><a class="reference internal" href="#what-kind-of-code-logtalk-generates-when-compiling-objects-dynamic-code-static-code">What kind of code Logtalk generates when compiling objects? Dynamic code? Static code?</a></li>
<li class="toctree-l3"><a class="reference internal" href="#how-about-message-sending-performance-does-logtalk-use-static-binding-or-dynamic-binding">How about message-sending performance? Does Logtalk use static binding or dynamic binding?</a></li>
<li class="toctree-l3"><a class="reference internal" href="#which-prolog-dependent-factors-are-most-crucial-for-good-logtalk-performance">Which Prolog-dependent factors are most crucial for good Logtalk performance?</a></li>
<li class="toctree-l3"><a class="reference internal" href="#how-does-logtalk-performance-compare-with-plain-prolog-and-with-prolog-modules">How does Logtalk performance compare with plain Prolog and with Prolog modules?</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="licensing.html">Licensing</a></li>
<li class="toctree-l2"><a class="reference internal" href="support.html">Support</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../devtools/index.html">Developer Tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../libraries/index.html">Libraries</a></li>
<li class="toctree-l1"><a class="reference internal" href="../ports/index.html">Ports</a></li>
<li class="toctree-l1"><a class="reference internal" href="../contributions/index.html">Contributions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../glossary.html">Glossary</a></li>
<li class="toctree-l1"><a class="reference internal" href="../bibliography.html">Bibliography</a></li>
<li class="toctree-l1"><a class="reference internal" href="../genindex.html">Index</a></li>
</ul>

    <p class="caption"><span class="caption-text">External Contents</span></p>
    <ul>
    <li class="toctree-l1"><a class="reference internal" href="../../apis/index.html">APIs</a></li>
    <li class="toctree-l1"><a class="reference internal" href="https://logtalk.org">Logtalk website</a></li>
    <li class="toctree-l1"><a class="reference internal" href="https://github.com/LogtalkDotOrg/logtalk3">GitHub repo</a></li>
    </ul>
  
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">The Logtalk Handbook</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../index.html" class="icon icon-home" aria-label="Home"></a></li>
          <li class="breadcrumb-item"><a href="index.html">FAQ</a></li>
      <li class="breadcrumb-item active">Performance</li>
      <li class="wy-breadcrumbs-aside">
              <a href="https://github.com/LogtalkDotOrg/logtalk3/blob/master/docs/handbook/sources/faq/performance.rst" class="fa fa-github"> Edit on GitHub</a>
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <section id="performance">
<span id="id1"></span><h1>Performance<a class="headerlink" href="#performance" title="Link to this heading"></a></h1>
<ul class="simple">
<li><p><a class="reference internal" href="#performance-meta-interpreter"><span class="std std-ref">Is Logtalk implemented as a meta-interpreter?</span></a></p></li>
<li><p><a class="reference internal" href="#performance-code-generated"><span class="std std-ref">What kind of code Logtalk generates when compiling objects? Dynamic code? Static code?</span></a></p></li>
<li><p><a class="reference internal" href="#performance-binding"><span class="std std-ref">How about message-sending performance? Does Logtalk use static binding or dynamic binding?</span></a></p></li>
<li><p><a class="reference internal" href="#performance-prolog"><span class="std std-ref">How does Logtalk performance compare with plain Prolog and with Prolog modules?</span></a></p></li>
</ul>
<section id="is-logtalk-implemented-as-a-meta-interpreter">
<span id="performance-meta-interpreter"></span><h2>Is Logtalk implemented as a meta-interpreter?<a class="headerlink" href="#is-logtalk-implemented-as-a-meta-interpreter" title="Link to this heading"></a></h2>
<p>No. Objects and their encapsulated predicates are compiled, not
meta-interpreted. In particular, inheritance relations are
pre-compiled for improved performance. Moreover, no meta-interpreter
is used even for objects compiled in debug mode.</p>
</section>
<section id="what-kind-of-code-logtalk-generates-when-compiling-objects-dynamic-code-static-code">
<span id="performance-code-generated"></span><h2>What kind of code Logtalk generates when compiling objects? Dynamic code? Static code?<a class="headerlink" href="#what-kind-of-code-logtalk-generates-when-compiling-objects-dynamic-code-static-code" title="Link to this heading"></a></h2>
<p>Static objects are compiled to static code. Static objects containing
dynamic predicates are also compiled to static code, except, of
course, for the dynamic predicates themselves. Dynamic objects are
necessarily compiled to dynamic code. As in Prolog programming, for
best performance, dynamic object predicates and dynamic objects
should only be used when truly needed.</p>
</section>
<section id="how-about-message-sending-performance-does-logtalk-use-static-binding-or-dynamic-binding">
<span id="performance-binding"></span><h2>How about message-sending performance? Does Logtalk use static binding or dynamic binding?<a class="headerlink" href="#how-about-message-sending-performance-does-logtalk-use-static-binding-or-dynamic-binding" title="Link to this heading"></a></h2>
<p>Logtalk supports both static binding and dynamic binding. When static
binding is not possible, Logtalk uses dynamic binding coupled with a
caching mechanism that avoids repeated lookups of predicate
declarations and predicate definitions. This is a solution common to
other programming languages supporting dynamic binding. Message
lookups are automatically cached the first time a message is sent.
Cache entries are automatically removed when loading entities or
using Logtalk dynamic features that invalidate the cached lookups.
Whenever static binding is used, message-sending performance is
essentially the same as a predicate call in plain Prolog. Performance
of dynamic binding when lookups are cached is close to the
performance that would be achieved with static binding. See the
User Manual section on <a class="reference internal" href="../userman/performance.html#performance-performance"><span class="std std-ref">performance</span></a>
for more details.</p>
</section>
<section id="which-prolog-dependent-factors-are-most-crucial-for-good-logtalk-performance">
<h2>Which Prolog-dependent factors are most crucial for good Logtalk performance?<a class="headerlink" href="#which-prolog-dependent-factors-are-most-crucial-for-good-logtalk-performance" title="Link to this heading"></a></h2>
<p>Logtalk compiles objects assuming first-argument indexing for static
code. First-argument indexing of dynamic code, when available, helps
to improve performance due to the automatic caching of method lookups
and the necessary use of book-keeping tables by the runtime engine
(this is specially important when using event-driven programming).
Dynamic objects and static objects containing dynamic predicates also
benefit from first-argument indexing of dynamic predicates. The
availability of multi-argument indexing, notably for dynamic
predicates, also benefits dynamic binding performance.</p>
</section>
<section id="how-does-logtalk-performance-compare-with-plain-prolog-and-with-prolog-modules">
<span id="performance-prolog"></span><h2>How does Logtalk performance compare with plain Prolog and with Prolog modules?<a class="headerlink" href="#how-does-logtalk-performance-compare-with-plain-prolog-and-with-prolog-modules" title="Link to this heading"></a></h2>
<p>Plain Prolog, Prolog modules, and Logtalk objects provide different
trade-offs between performance and features. In general, for a given
predicate definition, the best performance will be attained using
plain Prolog, second will be Prolog modules (assuming no explicitly
qualified calls are used), and finally Logtalk objects. Whenever
static binding is used, the performance of Logtalk is equal or close
to that of plain Prolog (depending on the Prolog virtual machine
implementation and compiler optimizations). See the
<a class="reference external" href="https://logtalk.org/performance.html">simple benchmark test results</a> using some
popular Prolog compilers.</p>
</section>
</section>


           </div>
          </div>
          <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
        <a href="deployment.html" class="btn btn-neutral float-left" title="Deployment" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="licensing.html" class="btn btn-neutral float-right" title="Licensing" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 1998-2025, Paulo Moura.</p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>